package org.gap.wizards.world.actions;

import java.util.HashMap;
import java.util.Map;

import org.gap.jseed.SeedContainer;
import org.gap.wizards.world.WorldAction;

public class Factory {
	public static final Factory PICK_UP = new Factory(PickupItemsAction.class);
	public static final Factory DROP_ITEM = new Factory(DropItemAction.class);
	public static final Factory OPEN_DOOR = new Factory(OpenDoorAction.class);
	public static final Factory CLOSE_DOOR = new Factory(CloseDoorAction.class);
	public static final Factory LOOK = new Factory(LookAction.class);
	public static final Factory WAIT = new Factory(WaitAction.class);
	public static final Factory APPLY_ITEM = new Factory(ApplyItemAction.class);
	public static final Factory CREATE_ELIXIR = new Factory(CreateElixerAction.class);
	public static final Factory EQUIP_ITEM = new Factory(EquipItemAction.class);
	public static final Factory FORAGING = new Factory(ForagingAction.class);
	public static final Factory TALK_WITH = new Factory(TalkWithAction.class);
	public static final Factory CLIMB_DOWN = new Factory(ClimbAction.class);
	public static final Factory CLIMB_UP = new Factory(ClimbAction.class);
	public static final Factory CAST_SPELL = new Factory(CastSpellAction.class);

	private static Map<Character, Factory> keyMap = new HashMap<Character, Factory>();
	private static SeedContainer store; 
	private final Class<? extends WorldAction> actionClass;
	
	static {
		keyMap.put(',', PICK_UP);
		keyMap.put('d', DROP_ITEM);
		keyMap.put('o', OPEN_DOOR);
		keyMap.put('c', CLOSE_DOOR);
		keyMap.put('.', WAIT);
		keyMap.put('L', LOOK);
		keyMap.put('a', APPLY_ITEM);
		keyMap.put('E', CREATE_ELIXIR);
		keyMap.put('e', EQUIP_ITEM);
		keyMap.put('f', FORAGING);
		keyMap.put('t', TALK_WITH);
		keyMap.put('>', CLIMB_DOWN);
		keyMap.put('<', CLIMB_UP);
		keyMap.put('z', CAST_SPELL);
		
	}
	
	public Factory(Class<? extends WorldAction> actionClass) {
		this.actionClass = actionClass;
	}
	
	public WorldAction createWorldAction() {
		return store.create(actionClass);
	}

	public static boolean accepts(char keyPress) {
		return keyMap.containsKey(keyPress);
	}

	public static Factory from(char keyPress) {
		return keyMap.get(keyPress);
	}

	public static void set(SeedContainer store) {
		Factory.store = store;

		store.register(TargetSelector.class);
	}
}
